package a.b.c;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;

import android.app.Activity;
import android.content.Context;
import android.hardware.SensorManager;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.util.Log;
import android.view.KeyEvent;

public class rankingview extends Activity {

	private WebView mWebView;
	SensorManager sensor;
	String in_mac;
	/** Called when the activity is first created. */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ranking);
		setLayout();
		
		in_mac = GetMacAddress();
		
		URL url= null;
		try {
			Log.i("1","2");
			url = new URL("http://220.67.128.23/Embedded/index.php?mac_address="+URLEncoder.encode(in_mac,"EUC-KR"));
			Log.i("1","3");
			url.openStream();
			Log.i("1","4");
			//finish();
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e){
			e.printStackTrace();
		}
		mWebView.getSettings().setJavaScriptEnabled(true);
		try {
			mWebView.loadUrl("http://220.67.128.23/Embedded/index.php?mac_address="+URLEncoder.encode(in_mac,"EUC-KR"));
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		mWebView.getSettings().setDefaultTextEncodingName("EUC-KR");
		mWebView.setWebViewClient(new WebViewClientClass());
		sensor = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
		
		
		
	}

	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
			mWebView.goBack();
			return true;
		}
		return super.onKeyDown(keyCode, event);
	}

	private class WebViewClientClass extends WebViewClient {
		@Override
		public boolean shouldOverrideUrlLoading(WebView view, String url) {
			view.loadUrl(url);
			return true;
		}
	}

	private void setLayout() {
		mWebView = (WebView) findViewById(R.id.web1);
	}
	
	 public String GetMacAddress()
	 {   
	    	WifiManager mngr = (WifiManager) this.getSystemService(Context.WIFI_SERVICE); 
	    	WifiInfo wifi = mngr.getConnectionInfo();   
	    	String addrMAC = wifi.getMacAddress();   
	    	return addrMAC;
	 } 
}